package com.open.capacity.study.controller;

import com.open.capacity.common.exception.controller.ControllerException;
import com.open.capacity.common.exception.service.ServiceException;
import com.open.capacity.common.model.Stage;
import com.open.capacity.common.model.SysTeaching;
import com.open.capacity.common.web.PageResult;
import com.open.capacity.common.web.Result;
import com.open.capacity.log.annotation.LogAnnotation;
import com.open.capacity.study.service.StageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/stage")
@Api(tags = "STAGE API")
public class StageController {
    @Autowired
    private StageService stageService;

    /**
     * 新增学习阶段
     * @param stage
     * @return
     * @throws ControllerException
     */
    @PostMapping("/insert")
    //权限注解（暂无）
    //@PreAuthorize("hasAnyAuthority('')")
    @LogAnnotation(module = "study-center", recordRequestParam = false)
    public Result insert(@RequestBody Stage stage) throws ControllerException {
        try {
            return stageService.insert(stage);
        }catch (ServiceException e){
            throw new ControllerException(e);
        }
    }

    /**
     * 修改阶段可用状态
     * @param params
     * @return
     * @throws ControllerException
     */
    @PostMapping("/delete")
    @ApiOperation(value = "修改阶段可用状态")
    //权限注解（暂无）
    //@PreAuthorize("hasAnyAuthority('')")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stcode", value = "体系code", required = true, dataType = "String"),
            @ApiImplicitParam(name = "status", value = "是否启用", required = true, dataType = "int")
    })
    @LogAnnotation(module = "study-center", recordRequestParam = false)
    public Result updateStatus(@RequestParam Map<String,Object> params) throws ControllerException{
        try {
            return stageService.updateStatus(params);
        }catch (ServiceException e){
            throw new ControllerException(e);
        }
    }

    /**
     * 修改阶段信息
     * @param stage
     * @return
     * @throws ControllerException
     */
    @PostMapping("/update")
    //权限注解（暂无）
    //@PreAuthorize("hasAnyAuthority('')")
    @LogAnnotation(module = "study-center", recordRequestParam = false)
    public Result update(@RequestBody Stage stage) throws ControllerException{
        try {
            return stageService.update(stage);
        }catch (ServiceException e){
            throw new ControllerException(e);
        }
    }

    /**
     * 查询体系内的阶段
     * @param params
     * @return
     * @throws ControllerException
     */
    @GetMapping("/getList")
    @ApiOperation(value = "阶段查询列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tsysId",value = "体系id",required = true,dataType = "Integer"),
            @ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer")
    })
    //权限注解（暂无）
    //@PreAuthorize("hasAnyAuthority('')")
    @LogAnnotation(module = "study-center", recordRequestParam = false)
    public PageResult<Stage> findTeaching(@RequestParam Map<String, Object> params) throws ControllerException{
        try {
            return stageService.findStage(params);
        } catch (ServiceException e) {
            throw new ControllerException(e);
        }
    }
}
